#include "wk_dma.h"








void memory_dma_copy(uint32_t src_buffer, uint32_t dst_buffer, uint16_t buffer_size, uint8_t data_width)
{
    dma_init_type dma_init_struct = {0};
    
    dma_reset(DMA2_CHANNEL2);
    dma_init_struct.buffer_size = buffer_size;
    dma_init_struct.direction = DMA_DIR_MEMORY_TO_MEMORY;
    dma_init_struct.memory_base_addr = (uint32_t)dst_buffer;
    dma_init_struct.memory_data_width = (dma_memory_data_size_type)DMA_MEMORY_DATA_WIDTH_WORD;
    dma_init_struct.memory_inc_enable = TRUE;
    dma_init_struct.peripheral_base_addr = (uint32_t)src_buffer;
    dma_init_struct.peripheral_data_width = (dma_peripheral_data_size_type)DMA_PERIPHERAL_DATA_WIDTH_WORD;
    dma_init_struct.peripheral_inc_enable = TRUE;
    dma_init_struct.priority = DMA_PRIORITY_VERY_HIGH;
    dma_init_struct.loop_mode_enable = FALSE;
    dma_init(DMA2_CHANNEL2, &dma_init_struct);
    
    dma_channel_enable(DMA2_CHANNEL2, TRUE);
}







void wk_dma_channel_config(dma_channel_type* dmax_channely, uint32_t peripheral_base_addr, uint32_t memory_base_addr, uint16_t buffer_size)
{
    dmax_channely->dtcnt = buffer_size;
    dmax_channely->paddr = peripheral_base_addr;
    dmax_channely->maddr = memory_base_addr;
}
